package com.wiim.tab;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.StateListDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TabElement extends LinearLayout {

	ImageView ivTabElement;
	TextView tvTabElement;
	LinearLayout lnSpecial;
	int zoomSizeDefault = 0;
	int heightElement = 20;
	public int widthElement;

	public TabElement(final Context c, final int drawable, final int drawableSelect, final String label, final boolean bSpecialType, final String lableSpec, final Boolean bTabletVersionLarge) {

		super(c);
		final float scale = this.getResources().getDisplayMetrics().density;
		this.ivTabElement = new ImageView(c);
		this.lnSpecial = new LinearLayout(c);
		if (bTabletVersionLarge) {
			this.zoomSizeDefault = 0;
			heightElement = 120;
		}
		StateListDrawable listDrawable = new StateListDrawable();
		listDrawable.addState(SELECTED_STATE_SET, this.getResources().getDrawable(drawableSelect));
		listDrawable.addState(ENABLED_STATE_SET, this.getResources().getDrawable(drawable));
		this.ivTabElement.setImageDrawable(listDrawable);
		this.ivTabElement.setBackgroundColor(Color.TRANSPARENT);
		this.ivTabElement.setLayoutParams(new LayoutParams((int) ((100 + this.zoomSizeDefault) * scale + 0.5f), (int) ((100 + this.zoomSizeDefault) * scale + 0.5f), (float) 0.0));
//		this.ivTabElement.setPadding(0, (int) (3 * scale + 0.5f), 0, 0);

		this.lnSpecial.setOrientation(LinearLayout.HORIZONTAL);
		this.lnSpecial.setGravity(Gravity.TOP);
		this.lnSpecial.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, (float) 0.0));
		this.lnSpecial.setBackgroundColor(Color.TRANSPARENT);

		if (bSpecialType) {
			this.tvTabElement = new TextView(c);
			this.tvTabElement.setText(lableSpec);
			this.tvTabElement.setTextSize((int) ((5 + this.zoomSizeDefault) * scale + 0.5f));
			this.tvTabElement.setTextColor(Color.YELLOW);
			this.tvTabElement.setTypeface(Typeface.DEFAULT_BOLD);
			this.tvTabElement.setGravity(Gravity.CENTER);
			this.tvTabElement.setLayoutParams(new LayoutParams((int) ((17 + this.zoomSizeDefault) * scale + 0.5f), (int) ((17 + this.zoomSizeDefault) * scale + 0.5f), (float) 0.0));
			tvTabElement.setMinWidth(20);
			tvTabElement.setPadding(2, 0, 2, 2);
			this.lnSpecial.addView(this.ivTabElement);
			this.lnSpecial.addView(this.tvTabElement);
		} else {
			this.lnSpecial.addView(this.ivTabElement);
		}

		this.tvTabElement = new TextView(c);
		this.tvTabElement.setText(label);
		this.tvTabElement.setGravity(Gravity.CENTER);
		this.tvTabElement.setBackgroundColor(Color.TRANSPARENT);
		this.tvTabElement.setTextColor(Color.WHITE);		
			this.tvTabElement.setTextSize((int) ((7 + this.zoomSizeDefault) * scale + 0.5f));
		this.tvTabElement.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, heightElement, (float) 1.0));
		this.setOrientation(LinearLayout.VERTICAL);
		this.setGravity(Gravity.CENTER);
		this.addView(this.lnSpecial);
		this.addView(this.tvTabElement);
		widthElement = tvTabElement.getWidth();
	}

	public TabElement(final Context c) {
		super(c);
		this.tvTabElement = new TextView(c);
		this.tvTabElement.setWidth(0);
		this.tvTabElement.setHeight(0);
		this.addView(this.tvTabElement);
	}

	public void changeTitle(final String title) {

		this.tvTabElement.setText(title);
	}
}
